package homelesspartners.client.widgets;

import homelesspartners.client.model.City;
import homelesspartners.client.model.Shelter;

import java.util.Iterator;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;


public class SheltersWidget extends Composite {

	private VerticalPanel verticalPanel = new VerticalPanel();
	private HTML heading = new HTML("&nbsp;<b>STEP 2 - Choose Shelter</b><br /><br />");
	private HTML subText = new HTML("Click on a shelter to read the personal stories of the homeless men and women staying at that shelter this winter.<br /><br />  You can return to this page and select another shelter at any time by clicking the <b>choose shelter</b> link above.<br /> <br />");
	private HTML transitPassRequest = new HTML("<br /><br />One item almost every homeless person needs is <b>Transit Tickets</b>.  They need them for going to job interviews, to make necessary appointments with agencies, doctors, etc.  Please consider, if possible, gifting transit tickets that can be distributed by the shelter staff to those who need it most, when it is needed most.<br /><br />");
	
	private static SheltersWidget instance = new SheltersWidget();
	
	public static SheltersWidget getInstance() {
		return instance;
	}

	public SheltersWidget() {
		verticalPanel.add(heading);
		verticalPanel.add(subText);
		initWidget(verticalPanel);
	}

	public void refresh(City aCity) {
		verticalPanel.clear();
		verticalPanel.add(heading);
		verticalPanel.add(subText);
		verticalPanel.add(new Label(" "));
		
		if(aCity.getShelters() == null){
			verticalPanel.add(new Label("Loading the shelters for this city, please wait..."));
			return;
		} else if (aCity.getShelters().size() == 0){
			verticalPanel.add(new HTML("No shelters have been setup for this city yet.  Please try again later, or you can <a href='./pages/samplestories.html' target='_blank'>read sample stories from last year's program</a>."));
			return;
		}
		
		for (Iterator sheltersList = aCity.getShelters().iterator(); sheltersList.hasNext();) {
			Shelter shelter = (Shelter) sheltersList.next();	
			ShelterWidget shelterWidget = new ShelterWidget(shelter);
			verticalPanel.add(shelterWidget);
		}			
		
		verticalPanel.add(transitPassRequest);
	}


	
	
}
